using DevExpress.XtraEditors;
using CSW.Framework.UI.DevEx;
using CSW.Security.UI.DevEx.Reports;

namespace CSW.Security.UI.DevEx.UserControls
{
    /// <summary>
    /// SecurityReportsUserControl
    /// </summary>
    public partial class SecurityReportUserControl : XtraUserControl
    {
        private readonly TypedGridController<RoleAppFunctionReport> m_RoleAppFunctionGrid;
        private readonly TypedGridController<UserRoleReport> m_UserRoleGrid;

        /// <summary>
        /// Initializes a new instance of the <see cref="SecurityReportUserControl"/> class.
        /// </summary>
        public SecurityReportUserControl()
        {
            InitializeComponent();

            // Role / App Function Report
            m_RoleAppFunctionGrid = new TypedGridController<RoleAppFunctionReport>(grdRoleAppFunctionReport, "RoleAppFunctionReport");
            m_RoleAppFunctionGrid.AddField("RoleID", "RoleID");
            m_RoleAppFunctionGrid.AddField("Role", "RoleDescription");
            m_RoleAppFunctionGrid.AddField("AppFunction", "AppFunctionDescription");

            // User Role Report
            m_UserRoleGrid = new TypedGridController<UserRoleReport>(grdUserRoleReport, "UserRoleReport");
            m_UserRoleGrid.AddField("UserID", "UserID");
            m_UserRoleGrid.AddField("First Name", "FirstName");
            m_UserRoleGrid.AddField("Last Name", "LastName");
            m_UserRoleGrid.AddField("Is App Support?", "IsAppSupport");
            m_UserRoleGrid.AddField("Role", "RoleDescription");
        }

        /// <summary>
        /// Refreshes the grids.
        /// </summary>
        public void RefreshGrids()
        {
            m_RoleAppFunctionGrid.DataSource = RoleAppFunctionReport.GetList();
            m_RoleAppFunctionGrid.BestFitColumns();

            m_UserRoleGrid.DataSource = UserRoleReport.GetList();
            m_UserRoleGrid.BestFitColumns();
        }
    }
}
